package com.cat.dataStructure03;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/apply-discount-every-n-orders/
 * @create 2025/11/16 16:06
 * @since JDK17
 */

class Cashier {
    int n, cnt, discount;
    Map<Integer, Integer> map = new HashMap<>();

    public Cashier(int n, int discount, int[] products, int[] prices) {
        this.n = n;
        this.discount = discount;
        for (int i = 0; i < products.length; i++) {
            map.put(products[i], prices[i]);
        }
    }

    public double getBill(int[] product, int[] amount) {
        double ans = 0, x = ++cnt == n ? discount : 0;
        for (int i = 0; i < product.length; i++) {
            int y = map.get(product[i]);
            ans += (y - (y * x) / 100) * amount[i];
        }
        cnt %= n;
        return ans;
    }
}
